*Note: this analysis was run using Stata 13.1 MP

use "wojewodztwo_data_4_replication.dta"

keep(wojewodstwo fips_admin red_priest_shr red_bishop5056 migrant_shr_01 yrs_ind_1797_1939_01 missing_bishop inst_vulner_ind ///
prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950 border_all border_land newborder_land border_germ)

lab var red_priest_shr "Patriot Priest share"
lab var red_bishop5056 "Patriot Bishop presence"
lab var migrant_shr_01 "Migrant share"
lab var yrs_ind_1797_1939 "Years Indep 1797-1939"
lab var prussian_empire "Prussian empire" 
lab var russian_empire "Russian empire" 
lab var habsburg_empire "Habsburg empire" 
lab var inst_vulner_ind "Institutional vulnerability"
lab var lnindustry_1950 "Industrialization 1950"
lab var urban_1950 "Urbanization 1950"
lab var educ_1950 "Education 1950"
lab var border_all "Border (any)"
lab var border_land "Land border"
lab var newborder_land "New land border"
lab var border_germ "German border"

*Figure 2 & Table A2 (models 1-4) Infiltration drivers (rank-and-file)
reg red_priest_shr inst_vulner_ind
outreg2 using taba2.doc, replace label dec(3) word symbol(**,*,#) nocons
reg red_priest_shr prussian_empire russian_empire
outreg2 using taba2.doc, append label dec(3) word symbol(**,*,#) nocons
reg red_priest_shr lnindustry_1950 urban_1950 educ_1950
outreg2 using taba2.doc, append label dec(3) word symbol(**,*,#) nocons
reg red_priest_shr inst_vulner_ind prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950
margins, at(inst_vulner_ind=(-.65)) saving(fileinfiltrat1)
margins, at(inst_vulner_ind=(1.68)) saving(fileinfiltrat2)
margins, at(prussian_empire=(0) russian_empire=(0)) saving(fileinfiltrat3)
margins, at(prussian_empire=(1) russian_empire=(0)) saving(fileinfiltrat4)
margins, at(prussian_empire=(0) russian_empire=(1)) saving(fileinfiltrat5)
margins, at(lnindustry_1950=(6.15)) saving(fileinfiltrat6)
margins, at(lnindustry_1950=(6.85)) saving(fileinfiltrat7)
margins, at(urban_1950=(.14)) saving(fileinfiltrat8)
margins, at(urban_1950=(.45)) saving(fileinfiltrat9)
margins, at(educ_1950=(2.87 )) saving(fileinfiltrat10)
margins, at(educ_1950=(4.48)) saving(fileinfiltrat11)
outreg2 using taba2.doc, append label dec(3) word symbol(**,*,#) nocons

clear all
use fileinfiltrat1.dta
recode * (*=.)
save fileinfiltrat0.dta

clear all
use "wojewodztwo_data_4_replication.dta"
combomarginsplot fileinfiltrat11 fileinfiltrat10 fileinfiltrat0 fileinfiltrat9 fileinfiltrat8 fileinfiltrat0 fileinfiltrat7  fileinfiltrat6   fileinfiltrat0 fileinfiltrat5 fileinfiltrat4 fileinfiltrat3 fileinfiltrat0 fileinfiltrat2 fileinfiltrat1 , ///
	title ("", size(medium)) ///
labels("High Education" "Low Education" " " "High Urbanization" "Low Urbanization" " " "High Industrialization" "Low Industrialization" " " "Russian Empire" "Prussian Empire" "Habsburg Empire" " " "High Organizational Vulnerability" "Low Organizational Vulnerability") ///
	recast(scatter) horiz ///
	ytitle(" ") yscale(range(0.5 15.5)) title("Figure 2: Drivers of Organizational Infiltration")  xtitle("Predicted Patriot Priest share", size(medium)) scheme(s2mono) 
	graph save redpriest_infiltration.gph

*Figure A1 & Table A2 (models 5-8) Infiltration drivers (rank-and-file)
reg red_bishop5056 inst_vulner_ind
outreg2 using taba2.doc, append label dec(3) word symbol(**,*,#) nocons
reg red_bishop5056 prussian_empire russian_empire
outreg2 using taba2.doc, append label dec(3) word symbol(**,*,#) nocons
reg red_bishop5056 lnindustry_1950 urban_1950 educ_1950
outreg2 using taba2.doc, append label dec(3) word symbol(**,*,#) nocons
reg red_bishop5056 inst_vulner_ind prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950
outreg2 using taba2.doc, append label dec(3) word symbol(**,*,#) nocons
margins, at(inst_vulner_ind=(-.65)) saving(filebishop1)
margins, at(inst_vulner_ind=(1.68)) saving(filebishop2)
margins, at(prussian_empire=(0) russian_empire=(0)) saving(filebishop3)
margins, at(prussian_empire=(1) russian_empire=(0)) saving(filebishop4)
margins, at(prussian_empire=(0) russian_empire=(1)) saving(filebishop5)
margins, at(lnindustry_1950=(6.15)) saving(filebishop6)
margins, at(lnindustry_1950=(6.85)) saving(filebishop7)
margins, at(urban_1950=(.14)) saving(filebishop8)
margins, at(urban_1950=(.45)) saving(filebishop9)
margins, at(educ_1950=(2.87 )) saving(filebishop10)
margins, at(educ_1950=(4.48)) saving(filebishop11)

combomarginsplot filebishop11 filebishop10 fileinfiltrat0 filebishop9 filebishop8 fileinfiltrat0 filebishop7  filebishop6   fileinfiltrat0 filebishop5 filebishop4 filebishop3 fileinfiltrat0 filebishop2 filebishop1 , ///
	title ("", size(medium)) ///
labels("High Education" "Low Education" " " "High Urbanization" "Low Urbanization" " " "High Industrialization" "Low Industrialization" " " "Russian Empire" "Prussian Empire" "Habsburg Empire" " " "Patriot bishop" "No Patriot bishop") ///
	recast(scatter) horiz ///
	ytitle(" ") yscale(range(0.5 15.5)) title("Figure A1: Drivers of Organizational Infiltration (Elite level)")  xtitle("Predicted Patriot bishop probability", size(medium)) scheme(s2mono) 
	graph save bishop_infiltration.gph



*Table A4 - disaggregated vulnerability indicators

reg red_priest_shr migrant_shr_01 prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950
outreg2 using tabvulner_st.doc, replace label dec(3) word symbol(**,*,#) nocons

reg red_priest_shr yrs_ind_1797_1939_01 prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950
outreg2 using tabvulner_st.doc, append label dec(3) word symbol(**,*,#) nocons

reg red_priest_shr missing_bishop prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950
outreg2 using tabvulner_st.doc, append label dec(3) word symbol(**,*,#) nocons

reg red_priest_shr migrant_shr_01 yrs_ind_1797_1939_01 prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950
outreg2 using tabvulner_st.doc, append label dec(3) word symbol(**,*,#) nocons

reg red_priest_shr migrant_shr_01 missing_bishop prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950
outreg2 using tabvulner_st.doc, append label dec(3) word symbol(**,*,#) nocons

reg red_priest_shr yrs_ind_1797_1939_01 missing_bishop prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950
outreg2 using tabvulner_st.doc, append label dec(3) word symbol(**,*,#) nocons

reg red_priest_shr migrant_shr_01 yrs_ind_1797_1939_01 missing_bishop prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950
outreg2 using tabvulner_st.doc, append label dec(3) word symbol(**,*,#) nocons



*Table A6 - controlling for borders
reg red_priest_shr inst_vulner_ind prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950
outreg2 using tab_border.doc, replace label dec(3) word symbol(**,*,#) nocons
reg red_priest_shr inst_vulner_ind border_all prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950
outreg2 using tab_border.doc, append label dec(3) word symbol(**,*,#) nocons
reg red_priest_shr inst_vulner_ind border_land prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950
outreg2 using tab_border.doc, append label dec(3) word symbol(**,*,#) nocons
reg red_priest_shr inst_vulner_ind newborder_land prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950
outreg2 using tab_border.doc, append label dec(3) word symbol(**,*,#) nocons
reg red_priest_shr inst_vulner_ind border_germ prussian_empire russian_empire lnindustry_1950 urban_1950 educ_1950
outreg2 using tab_border.doc, append label dec(3) word symbol(**,*,#) nocons





